package com.xinxing.city.recovery.ui;

import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Toast;

import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;
import androidx.databinding.DataBindingUtil;

import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;
import com.xinxing.city.recovery.R;
import com.xinxing.city.recovery.databinding.ActivitySetDevenaBinding;

import com.xinxing.city.recovery.entitys.Devena;
import com.xinxing.city.recovery.utils.SharedPreferencesUtils;

import java.lang.reflect.Type;

public class SetDevenaActivity extends AppCompatActivity {
    private ActivitySetDevenaBinding mDataBind;
    private Gson gson;
    Devena devena = new Devena();
    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        mDataBind = DataBindingUtil.setContentView(this, R.layout.activity_set_devena);
        gson = new Gson();
        init();
        mDataBind.setDevena(devena);
    }
    private void init(){
        String devenaStr = (String) SharedPreferencesUtils.getParam(this,"set_devena","");
        if(!devenaStr.equals("")){
            Type dev = new TypeToken<Devena>() {}.getType();
            devena = gson.fromJson(devenaStr,dev);
        }
    }

    /**
     * 展开/隐藏 回收桶
     * @param view
     */
    public void hstSH(View view){
        if (mDataBind.hstDetail.getVisibility() == View.VISIBLE) {
            mDataBind.hstDetail.setVisibility(View.GONE);
            mDataBind.arrow.setImageResource(R.drawable.icon_right_1);
        } else {
            mDataBind.hstDetail.setVisibility(View.VISIBLE);
            mDataBind.arrow.setImageResource(R.drawable.icon_down_1);
        }
    }

    /**
     * 保存
     * @param view
     */
    public void saveSub(View view){
        SharedPreferencesUtils.setParam(this,"set_devena",gson.toJson(devena));
        Toast.makeText(this,"保存成功",Toast.LENGTH_SHORT).show();
        SetDevenaActivity.this.finish();
    }
}
